package com.geeke.wf.controller;

import java.util.List;

import org.camunda.bpm.engine.rest.dto.CountResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.geeke.common.controller.BaseController;
import com.geeke.utils.SessionUtils;
import com.geeke.wf.dto.HistoricTaskQueryDto;
import com.geeke.wf.entity.HistTask;
import com.geeke.wf.service.HistTaskService;


/**
 * 流程实例 Controller
 * @author lys
 * @version 2020-04-30
 */
@RestController
@RequestMapping(value = "/wf/history")
public class HistTaskController extends BaseController {

	@Autowired
	HistTaskService histTaskService;

    @PostMapping("/task")
    public List<HistTask> queryHistoricTaskInstances(
		@RequestBody HistoricTaskQueryDto queryDto,
		@RequestParam("firstResult") int firstResult,
		@RequestParam("maxResults") int maxResults
	){
		// 任务所属人限定在当前登录人
		String userId = SessionUtils.getUser().getId();
		queryDto.setTaskOwner(userId);

		List<HistTask> result = histTaskService.queryHistoricTaskInstances(queryDto, firstResult, maxResults);
		return result; 
    }

	@PostMapping("/task/count")  
	public CountResultDto queryHistoricTaskInstancesCount(@RequestBody HistoricTaskQueryDto queryDto) {
		// 任务所属人限定在当前登录人
		String userId = SessionUtils.getUser().getId();
		queryDto.setTaskOwner(userId);
		long count = histTaskService.queryHistoricTaskInstancesCount(queryDto);

		CountResultDto result = new CountResultDto();
		result.setCount(count);
	
		return result;
	}
    
}